package com.jiawa.wiki.controller;

import com.jiawa.wiki.req.EbookQueryReq;
import com.jiawa.wiki.req.EbookSaveReq;
import com.jiawa.wiki.resp.CommonResp;
import com.jiawa.wiki.resp.EbookResp;
import com.jiawa.wiki.resp.PageResp;
import com.jiawa.wiki.service.EbookService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/ebook")
public class EbookController {


    @Resource
    public EbookService ebookService;

    @GetMapping("/list")
    public CommonResp<PageResp<EbookResp>> list(EbookQueryReq req) {
        PageResp<EbookResp> list = ebookService.getlist(req);
        CommonResp<PageResp<EbookResp>> resp = new CommonResp<>();

        resp.setContent(list);
        return resp;
    }

    @PostMapping("/list")
    public CommonResp save(@RequestBody EbookQueryReq req) {
        ebookService.save(req);
        CommonResp resp = new CommonResp<>();
        return resp;
    }

    //删除
    @DeleteMapping("/delete/{id}")
    public CommonResp delete(@PathVariable long id) {
        ebookService.delete(id);
        CommonResp resp = new CommonResp<>();
        return resp;
    }

}